package excercise.recursive;

import java.util.ArrayList;
import java.util.List;

/**
 * 子集
 */
public class Question2_2 {

    public void solution(String str) {
        char[] arr = str.toCharArray();
        List<String> r = new ArrayList<>();
        List<String> path = new ArrayList<>();
        f(0, arr, path, r);

        r.forEach(System.out::println);
    }

    public void f(int curLen, char[] arr, List<String> path, List<String> r) {
        r.add(getPath(path));

        for (int i = curLen; i < arr.length; i++) {
            path.add(String.valueOf(arr[i]));
            f(i + 1, arr, path, r);

            path.remove(path.size() - 1);
        }
    }

    public String getPath(List<String> path) {
        StringBuilder s = new StringBuilder();
        for (String value : path) {
            s.append(value);
        }
        return s.toString();
    }

    public static void main(String[] args) {
        Question2_2 question2 = new Question2_2();
        question2.solution("abc");
    }
}
